{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cells': [{'cell_type': 'code',\n",
       "   'execution_count': 6,\n",
       "   'metadata': {},\n",
       "   'outputs': [],\n",
       "   'source': ['import os\\n',\n",
       "    'import tkinter\\n',\n",
       "    'import tkinter.simpledialog\\n',\n",
       "    'import tkinter.colorchooser\\n',\n",
       "    'import tkinter.filedialog\\n',\n",
       "    '#需要执行pip install pillow安装扩展库\\n',\n",
       "    'from PIL import ImageGrab\\n',\n",
       "    '\\n',\n",
       "    'root = tkinter.Tk()\\n',\n",
       "    \"root.title('My Paint----by Dong Fuguo')\\n\",\n",
       "    \"root['width'] = 800\\n\",\n",
       "    \"root['height'] = 600\\n\",\n",
       "    '\\n',\n",
       "    '#控制是否允许画图的变量，1：允许，0：不允许\\n',\n",
       "    'canDraw = tkinter.IntVar(value=0)\\n',\n",
       "    '\\n',\n",
       "    '#控制画图类型的变量，1：曲线，2：直线，3：矩形，4：文本，5：橡皮\\n',\n",
       "    'what = tkinter.IntVar(value=1)\\n',\n",
       "    '\\n',\n",
       "    '#记录鼠标位置的变量\\n',\n",
       "    'X = tkinter.IntVar(value=0)\\n',\n",
       "    'Y = tkinter.IntVar(value=0)\\n',\n",
       "    '\\n',\n",
       "    '#前景色、背景色\\n',\n",
       "    \"foreColor = '#000000'\\n\",\n",
       "    \"backColor = '#FFFFFF'\\n\",\n",
       "    '\\n',\n",
       "    '#创建画布\\n',\n",
       "    'image = tkinter.PhotoImage()\\n',\n",
       "    'canvas = tkinter.Canvas(root,\\n',\n",
       "    \"                          bg='white',\\n\",\n",
       "    '                          width=800, height=600)\\n',\n",
       "    'canvas.create_image(800, 600, image=image)\\n',\n",
       "    '\\n',\n",
       "    '#鼠标左键单击，允许画图，并记录当前鼠标位置\\n',\n",
       "    'def onLeftButtonDown(event):\\n',\n",
       "    '    canDraw.set(1)\\n',\n",
       "    '    X.set(event.x)\\n',\n",
       "    '    Y.set(event.y)\\n',\n",
       "    '    if what.get()==4:\\n',\n",
       "    '        canvas.create_text(event.x, event.y, text=text)\\n',\n",
       "    \"canvas.bind('<Button-1>', onLeftButtonDown)\\n\",\n",
       "    '\\n',\n",
       "    '#记录最后绘制图形的id\\n',\n",
       "    'lastDraw = 0\\n',\n",
       "    '#按住鼠标左键移动，画图\\n',\n",
       "    'def onLeftButtonMove(event):\\n',\n",
       "    '    global lastDraw\\n',\n",
       "    '    if canDraw.get()==0:\\n',\n",
       "    '        return\\n',\n",
       "    '    if what.get()==2 or what.get()==3 or what.get()==6:\\n',\n",
       "    '        #先删除刚刚画过的，再画新的\\n',\n",
       "    '        try:\\n',\n",
       "    '            canvas.delete(lastDraw)\\n',\n",
       "    '        except Exception as e:\\n',\n",
       "    '            pass\\n',\n",
       "    '\\n',\n",
       "    '    if what.get()==1:\\n',\n",
       "    '        #使用当前选择的前景色绘制曲线\\n',\n",
       "    '        canvas.create_line(X.get(),\\n',\n",
       "    '                             Y.get(),\\n',\n",
       "    '                             event.x,\\n',\n",
       "    '                             event.y,\\n',\n",
       "    '                             fill=foreColor)\\n',\n",
       "    '        X.set(event.x)\\n',\n",
       "    '        Y.set(event.y)\\n',\n",
       "    '    \\n',\n",
       "    '    elif what.get()==2:\\n',\n",
       "    '        #绘制直线\\n',\n",
       "    '        lastDraw = canvas.create_line(X.get(),\\n',\n",
       "    '                                         Y.get(),\\n',\n",
       "    '                                         event.x,\\n',\n",
       "    '                                         event.y,\\n',\n",
       "    '                                         fill=foreColor)\\n',\n",
       "    '    elif what.get()==3:\\n',\n",
       "    '        #绘制矩形\\n',\n",
       "    '        lastDraw = canvas.create_rectangle(X.get(),\\n',\n",
       "    '                                              Y.get(),\\n',\n",
       "    '                                              event.x,\\n',\n",
       "    '                                              event.y,\\n',\n",
       "    '                                              fill=backColor,\\n',\n",
       "    '                                              outline=foreColor)\\n',\n",
       "    '    elif what.get()==6:\\n',\n",
       "    '        #绘制园\\n',\n",
       "    '        lastDraw = canvas.create_oval(\\n',\n",
       "    '                X.get(),\\n',\n",
       "    '                Y.get(),\\n',\n",
       "    '                event.x,\\n',\n",
       "    '                event.y,\\n',\n",
       "    '                fill=backColor,\\n',\n",
       "    '                outline=foreColor\\n',\n",
       "    '            )\\n',\n",
       "    '\\n',\n",
       "    '    elif what.get()==5:\\n',\n",
       "    '        #橡皮，使用背景色填充10*10的矩形区域\\n',\n",
       "    '        canvas.create_rectangle(event.x-5,\\n',\n",
       "    '                                   event.y-5,\\n',\n",
       "    '                                   event.x+5,\\n',\n",
       "    '                                   event.y+5,\\n',\n",
       "    '                                   outline=backColor,\\n',\n",
       "    '                                   fill=backColor)\\n',\n",
       "    \"canvas.bind('<B1-Motion>', onLeftButtonMove)\\n\",\n",
       "    '\\n',\n",
       "    '#鼠标左键抬起，不允许再画图了\\n',\n",
       "    'def onLeftButtonUp(event):\\n',\n",
       "    '    canDraw.set(0)\\n',\n",
       "    '    global lastDraw\\n',\n",
       "    '    #防止切换图形时误删上次绘制的图形\\n',\n",
       "    '    lastDraw = 0\\n',\n",
       "    \"canvas.bind('<ButtonRelease-1>', onLeftButtonUp)\\n\",\n",
       "    '\\n',\n",
       "    '#创建菜单\\n',\n",
       "    'menu = tkinter.Menu(root, tearoff=0)\\n',\n",
       "    '#打开图像文件\\n',\n",
       "    'def Open():\\n',\n",
       "    \"    filename = tkinter.filedialog.askopenfilename(title='Open Image',\\n\",\n",
       "    \"                            filetypes=[('image', '*.jpg *.png *.gif')])\\n\",\n",
       "    '    if filename:\\n',\n",
       "    '        global image\\n',\n",
       "    '        image = tkinter.PhotoImage(file=filename)\\n',\n",
       "    '        canvas.create_image(80, 80, image=image)\\n',\n",
       "    \"menu.add_command(label='Open', command=Open)\\n\",\n",
       "    '\\n',\n",
       "    'def Save():\\n',\n",
       "    '    #获取客户区域位置和尺寸，并截图保存\\n',\n",
       "    '    left = int(root.winfo_rootx())\\n',\n",
       "    '    top = int(root.winfo_rooty())\\n',\n",
       "    '    width = root.winfo_width()\\n',\n",
       "    '    height = root.winfo_height()\\n',\n",
       "    '    im = ImageGrab.grab((left,top,left+width,top+height))\\n',\n",
       "    '    \\n',\n",
       "    '    #保存绘制的图片\\n',\n",
       "    \"    filename = tkinter.filedialog.asksaveasfilename(title='保存图片',\\n\",\n",
       "    \"                                       filetypes=[('图片文件','*.png')])\\n\",\n",
       "    '    if not filename:\\n',\n",
       "    '        return\\n',\n",
       "    \"    if not filename.endswith('.png'):\\n\",\n",
       "    \"        filename = filename+'.png'\\n\",\n",
       "    '    \\n',\n",
       "    '    im.save(filename)\\n',\n",
       "    \"menu.add_command(label='Save', command=Save)\\n\",\n",
       "    '\\n',\n",
       "    '#添加菜单，清除，遍历画布上的所有图像，逐个删除\\n',\n",
       "    'def Clear():\\n',\n",
       "    '    for item in canvas.find_all():\\n',\n",
       "    '        canvas.delete(item)\\n',\n",
       "    \"menu.add_command(label='Clear', command=Clear)\\n\",\n",
       "    '\\n',\n",
       "    '#添加分割线\\n',\n",
       "    'menu.add_separator()\\n',\n",
       "    '\\n',\n",
       "    '#创建子菜单，用来选择绘图类型\\n',\n",
       "    'menuType = tkinter.Menu(menu, tearoff=0)\\n',\n",
       "    'def drawCurve():\\n',\n",
       "    '    what.set(1)\\n',\n",
       "    \"menuType.add_command(label='Curve', command=drawCurve)\\n\",\n",
       "    '\\n',\n",
       "    'def drawLine():\\n',\n",
       "    '    what.set(2)\\n',\n",
       "    \"menuType.add_command(label='Line', command=drawLine)\\n\",\n",
       "    '\\n',\n",
       "    '\\n',\n",
       "    'def drawRectangle():\\n',\n",
       "    '    what.set(3)\\n',\n",
       "    \"menuType.add_command(label='Rectangle', command=drawRectangle)\\n\",\n",
       "    '\\n',\n",
       "    'def drawCircle():\\n',\n",
       "    '    what.set(6)\\n',\n",
       "    \"menuType.add_command(label='园', command=drawCircle)\\n\",\n",
       "    '\\n',\n",
       "    'def drawText():\\n',\n",
       "    '    global text\\n',\n",
       "    \"    text = tkinter.simpledialog.askstring(title='Input what you want to draw', prompt='')\\n\",\n",
       "    '    what.set(4)\\n',\n",
       "    \"menuType.add_command(label='Text', command=drawText)\\n\",\n",
       "    '\\n',\n",
       "    'menuType.add_separator()\\n',\n",
       "    '\\n',\n",
       "    '#选择前景色\\n',\n",
       "    'def chooseForeColor():\\n',\n",
       "    '    global foreColor\\n',\n",
       "    '    foreColor = tkinter.colorchooser.askcolor()[1]\\n',\n",
       "    \"menuType.add_command(label='Choose Foreground Color',\\n\",\n",
       "    '                       command=chooseForeColor)\\n',\n",
       "    '\\n',\n",
       "    '#选择背景色\\n',\n",
       "    'def chooseBackColor():\\n',\n",
       "    '    global backColor\\n',\n",
       "    '    backColor = tkinter.colorchooser.askcolor()[1]\\n',\n",
       "    \"menuType.add_command(label='Choose Background Color',\\n\",\n",
       "    '                       command=chooseBackColor)\\n',\n",
       "    '\\n',\n",
       "    '#橡皮\\n',\n",
       "    'def onErase():\\n',\n",
       "    '    what.set(5)\\n',\n",
       "    \"menuType.add_command(label='Erase', command=onErase)\\n\",\n",
       "    '\\n',\n",
       "    \"menu.add_cascade(label='Type', menu=menuType)\\n\",\n",
       "    '\\n',\n",
       "    '#鼠标右键抬起，弹出菜单\\n',\n",
       "    'def onRightButtonUp(event):\\n',\n",
       "    '    menu.post(event.x_root, event.y_root)\\n',\n",
       "    \"canvas.bind('<ButtonRelease-3>', onRightButtonUp)\\n\",\n",
       "    '\\n',\n",
       "    'canvas.pack(fill=tkinter.BOTH, expand=tkinter.YES)\\n',\n",
       "    '\\n',\n",
       "    '#启动应用程序\\n',\n",
       "    'root.mainloop()\\n']}],\n",
       " 'metadata': {'kernelspec': {'display_name': 'Python 3',\n",
       "   'language': 'python',\n",
       "   'name': 'python3'},\n",
       "  'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 3},\n",
       "   'file_extension': '.py',\n",
       "   'mimetype': 'text/x-python',\n",
       "   'name': 'python',\n",
       "   'nbconvert_exporter': 'python',\n",
       "   'pygments_lexer': 'ipython3',\n",
       "   'version': '3.12.6'}},\n",
       " 'nbformat': 4,\n",
       " 'nbformat_minor': 2}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 6,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"import os\\n\",\n",
    "    \"import tkinter\\n\",\n",
    "    \"import tkinter.simpledialog\\n\",\n",
    "    \"import tkinter.colorchooser\\n\",\n",
    "    \"import tkinter.filedialog\\n\",\n",
    "    \"#需要执行pip install pillow安装扩展库\\n\",\n",
    "    \"from PIL import ImageGrab\\n\",\n",
    "    \"\\n\",\n",
    "    \"root = tkinter.Tk()\\n\",\n",
    "    \"root.title('My Paint----by Dong Fuguo')\\n\",\n",
    "    \"root['width'] = 800\\n\",\n",
    "    \"root['height'] = 600\\n\",\n",
    "    \"\\n\",\n",
    "    \"#控制是否允许画图的变量，1：允许，0：不允许\\n\",\n",
    "    \"canDraw = tkinter.IntVar(value=0)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#控制画图类型的变量，1：曲线，2：直线，3：矩形，4：文本，5：橡皮\\n\",\n",
    "    \"what = tkinter.IntVar(value=1)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#记录鼠标位置的变量\\n\",\n",
    "    \"X = tkinter.IntVar(value=0)\\n\",\n",
    "    \"Y = tkinter.IntVar(value=0)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#前景色、背景色\\n\",\n",
    "    \"foreColor = '#000000'\\n\",\n",
    "    \"backColor = '#FFFFFF'\\n\",\n",
    "    \"\\n\",\n",
    "    \"#创建画布\\n\",\n",
    "    \"image = tkinter.PhotoImage()\\n\",\n",
    "    \"canvas = tkinter.Canvas(root,\\n\",\n",
    "    \"                          bg='white',\\n\",\n",
    "    \"                          width=800, height=600)\\n\",\n",
    "    \"canvas.create_image(800, 600, image=image)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#鼠标左键单击，允许画图，并记录当前鼠标位置\\n\",\n",
    "    \"def onLeftButtonDown(event):\\n\",\n",
    "    \"    canDraw.set(1)\\n\",\n",
    "    \"    X.set(event.x)\\n\",\n",
    "    \"    Y.set(event.y)\\n\",\n",
    "    \"    if what.get()==4:\\n\",\n",
    "    \"        canvas.create_text(event.x, event.y, text=text)\\n\",\n",
    "    \"canvas.bind('<Button-1>', onLeftButtonDown)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#记录最后绘制图形的id\\n\",\n",
    "    \"lastDraw = 0\\n\",\n",
    "    \"#按住鼠标左键移动，画图\\n\",\n",
    "    \"def onLeftButtonMove(event):\\n\",\n",
    "    \"    global lastDraw\\n\",\n",
    "    \"    if canDraw.get()==0:\\n\",\n",
    "    \"        return\\n\",\n",
    "    \"    if what.get()==2 or what.get()==3 or what.get()==6:\\n\",\n",
    "    \"        #先删除刚刚画过的，再画新的\\n\",\n",
    "    \"        try:\\n\",\n",
    "    \"            canvas.delete(lastDraw)\\n\",\n",
    "    \"        except Exception as e:\\n\",\n",
    "    \"            pass\\n\",\n",
    "    \"\\n\",\n",
    "    \"    if what.get()==1:\\n\",\n",
    "    \"        #使用当前选择的前景色绘制曲线\\n\",\n",
    "    \"        canvas.create_line(X.get(),\\n\",\n",
    "    \"                             Y.get(),\\n\",\n",
    "    \"                             event.x,\\n\",\n",
    "    \"                             event.y,\\n\",\n",
    "    \"                             fill=foreColor)\\n\",\n",
    "    \"        X.set(event.x)\\n\",\n",
    "    \"        Y.set(event.y)\\n\",\n",
    "    \"    \\n\",\n",
    "    \"    elif what.get()==2:\\n\",\n",
    "    \"        #绘制直线\\n\",\n",
    "    \"        lastDraw = canvas.create_line(X.get(),\\n\",\n",
    "    \"                                         Y.get(),\\n\",\n",
    "    \"                                         event.x,\\n\",\n",
    "    \"                                         event.y,\\n\",\n",
    "    \"                                         fill=foreColor)\\n\",\n",
    "    \"    elif what.get()==3:\\n\",\n",
    "    \"        #绘制矩形\\n\",\n",
    "    \"        lastDraw = canvas.create_rectangle(X.get(),\\n\",\n",
    "    \"                                              Y.get(),\\n\",\n",
    "    \"                                              event.x,\\n\",\n",
    "    \"                                              event.y,\\n\",\n",
    "    \"                                              fill=backColor,\\n\",\n",
    "    \"                                              outline=foreColor)\\n\",\n",
    "    \"    elif what.get()==6:\\n\",\n",
    "    \"        #绘制园\\n\",\n",
    "    \"        lastDraw = canvas.create_oval(\\n\",\n",
    "    \"                X.get(),\\n\",\n",
    "    \"                Y.get(),\\n\",\n",
    "    \"                event.x,\\n\",\n",
    "    \"                event.y,\\n\",\n",
    "    \"                fill=backColor,\\n\",\n",
    "    \"                outline=foreColor\\n\",\n",
    "    \"            )\\n\",\n",
    "    \"\\n\",\n",
    "    \"    elif what.get()==5:\\n\",\n",
    "    \"        #橡皮，使用背景色填充10*10的矩形区域\\n\",\n",
    "    \"        canvas.create_rectangle(event.x-5,\\n\",\n",
    "    \"                                   event.y-5,\\n\",\n",
    "    \"                                   event.x+5,\\n\",\n",
    "    \"                                   event.y+5,\\n\",\n",
    "    \"                                   outline=backColor,\\n\",\n",
    "    \"                                   fill=backColor)\\n\",\n",
    "    \"canvas.bind('<B1-Motion>', onLeftButtonMove)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#鼠标左键抬起，不允许再画图了\\n\",\n",
    "    \"def onLeftButtonUp(event):\\n\",\n",
    "    \"    canDraw.set(0)\\n\",\n",
    "    \"    global lastDraw\\n\",\n",
    "    \"    #防止切换图形时误删上次绘制的图形\\n\",\n",
    "    \"    lastDraw = 0\\n\",\n",
    "    \"canvas.bind('<ButtonRelease-1>', onLeftButtonUp)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#创建菜单\\n\",\n",
    "    \"menu = tkinter.Menu(root, tearoff=0)\\n\",\n",
    "    \"#打开图像文件\\n\",\n",
    "    \"def Open():\\n\",\n",
    "    \"    filename = tkinter.filedialog.askopenfilename(title='Open Image',\\n\",\n",
    "    \"                            filetypes=[('image', '*.jpg *.png *.gif')])\\n\",\n",
    "    \"    if filename:\\n\",\n",
    "    \"        global image\\n\",\n",
    "    \"        image = tkinter.PhotoImage(file=filename)\\n\",\n",
    "    \"        canvas.create_image(80, 80, image=image)\\n\",\n",
    "    \"menu.add_command(label='Open', command=Open)\\n\",\n",
    "    \"\\n\",\n",
    "    \"def Save():\\n\",\n",
    "    \"    #获取客户区域位置和尺寸，并截图保存\\n\",\n",
    "    \"    left = int(root.winfo_rootx())\\n\",\n",
    "    \"    top = int(root.winfo_rooty())\\n\",\n",
    "    \"    width = root.winfo_width()\\n\",\n",
    "    \"    height = root.winfo_height()\\n\",\n",
    "    \"    im = ImageGrab.grab((left,top,left+width,top+height))\\n\",\n",
    "    \"    \\n\",\n",
    "    \"    #保存绘制的图片\\n\",\n",
    "    \"    filename = tkinter.filedialog.asksaveasfilename(title='保存图片',\\n\",\n",
    "    \"                                       filetypes=[('图片文件','*.png')])\\n\",\n",
    "    \"    if not filename:\\n\",\n",
    "    \"        return\\n\",\n",
    "    \"    if not filename.endswith('.png'):\\n\",\n",
    "    \"        filename = filename+'.png'\\n\",\n",
    "    \"    \\n\",\n",
    "    \"    im.save(filename)\\n\",\n",
    "    \"menu.add_command(label='Save', command=Save)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#添加菜单，清除，遍历画布上的所有图像，逐个删除\\n\",\n",
    "    \"def Clear():\\n\",\n",
    "    \"    for item in canvas.find_all():\\n\",\n",
    "    \"        canvas.delete(item)\\n\",\n",
    "    \"menu.add_command(label='Clear', command=Clear)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#添加分割线\\n\",\n",
    "    \"menu.add_separator()\\n\",\n",
    "    \"\\n\",\n",
    "    \"#创建子菜单，用来选择绘图类型\\n\",\n",
    "    \"menuType = tkinter.Menu(menu, tearoff=0)\\n\",\n",
    "    \"def drawCurve():\\n\",\n",
    "    \"    what.set(1)\\n\",\n",
    "    \"menuType.add_command(label='Curve', command=drawCurve)\\n\",\n",
    "    \"\\n\",\n",
    "    \"def drawLine():\\n\",\n",
    "    \"    what.set(2)\\n\",\n",
    "    \"menuType.add_command(label='Line', command=drawLine)\\n\",\n",
    "    \"\\n\",\n",
    "    \"\\n\",\n",
    "    \"def drawRectangle():\\n\",\n",
    "    \"    what.set(3)\\n\",\n",
    "    \"menuType.add_command(label='Rectangle', command=drawRectangle)\\n\",\n",
    "    \"\\n\",\n",
    "    \"def drawCircle():\\n\",\n",
    "    \"    what.set(6)\\n\",\n",
    "    \"menuType.add_command(label='园', command=drawCircle)\\n\",\n",
    "    \"\\n\",\n",
    "    \"def drawText():\\n\",\n",
    "    \"    global text\\n\",\n",
    "    \"    text = tkinter.simpledialog.askstring(title='Input what you want to draw', prompt='')\\n\",\n",
    "    \"    what.set(4)\\n\",\n",
    "    \"menuType.add_command(label='Text', command=drawText)\\n\",\n",
    "    \"\\n\",\n",
    "    \"menuType.add_separator()\\n\",\n",
    "    \"\\n\",\n",
    "    \"#选择前景色\\n\",\n",
    "    \"def chooseForeColor():\\n\",\n",
    "    \"    global foreColor\\n\",\n",
    "    \"    foreColor = tkinter.colorchooser.askcolor()[1]\\n\",\n",
    "    \"menuType.add_command(label='Choose Foreground Color',\\n\",\n",
    "    \"                       command=chooseForeColor)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#选择背景色\\n\",\n",
    "    \"def chooseBackColor():\\n\",\n",
    "    \"    global backColor\\n\",\n",
    "    \"    backColor = tkinter.colorchooser.askcolor()[1]\\n\",\n",
    "    \"menuType.add_command(label='Choose Background Color',\\n\",\n",
    "    \"                       command=chooseBackColor)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#橡皮\\n\",\n",
    "    \"def onErase():\\n\",\n",
    "    \"    what.set(5)\\n\",\n",
    "    \"menuType.add_command(label='Erase', command=onErase)\\n\",\n",
    "    \"\\n\",\n",
    "    \"menu.add_cascade(label='Type', menu=menuType)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#鼠标右键抬起，弹出菜单\\n\",\n",
    "    \"def onRightButtonUp(event):\\n\",\n",
    "    \"    menu.post(event.x_root, event.y_root)\\n\",\n",
    "    \"canvas.bind('<ButtonRelease-3>', onRightButtonUp)\\n\",\n",
    "    \"\\n\",\n",
    "    \"canvas.pack(fill=tkinter.BOTH, expand=tkinter.YES)\\n\",\n",
    "    \"\\n\",\n",
    "    \"#启动应用程序\\n\",\n",
    "    \"root.mainloop()\\n\"\n",
    "   ]\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {\n",
    "  \"kernelspec\": {\n",
    "   \"display_name\": \"Python 3\",\n",
    "   \"language\": \"python\",\n",
    "   \"name\": \"python3\"\n",
    "  },\n",
    "  \"language_info\": {\n",
    "   \"codemirror_mode\": {\n",
    "    \"name\": \"ipython\",\n",
    "    \"version\": 3\n",
    "   },\n",
    "   \"file_extension\": \".py\",\n",
    "   \"mimetype\": \"text/x-python\",\n",
    "   \"name\": \"python\",\n",
    "   \"nbconvert_exporter\": \"python\",\n",
    "   \"pygments_lexer\": \"ipython3\",\n",
    "   \"version\": \"3.12.6\"\n",
    "  }\n",
    " },\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 2\n",
    "}\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
